package com.cheyun.netsalev3.view

import android.content.Intent
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.MyAdapter
import com.cheyun.netsalev3.adapter.MyPagedListAdapter
import com.cheyun.netsalev3.bean.CarBrandParam
import com.cheyun.netsalev3.bean.Data
import com.cheyun.netsalev3.bean.EditDriveParam
import com.cheyun.netsalev3.bean.order.OrderKeliuData
import com.cheyun.netsalev3.databinding.ActivityChoiceCustomerBinding
import com.cheyun.netsalev3.databinding.ActivityChoiceDriveTimeBinding
import com.cheyun.netsalev3.databinding.ActivityChoiceOrderCustomerBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.InjectorUtils
import com.cheyun.netsalev3.utils.SpaceItemDecoration
import com.cheyun.netsalev3.utils.api.NetworkState
import com.cheyun.netsalev3.viewmodel.ChoiceDriveTimeActivityViewModel
import com.cheyun.netsalev3.viewmodel.ChoiceOrderCustomerActivityViewModel

class ChoiceDriveTimeActivity : BaseActivity<ActivityChoiceDriveTimeBinding>() {
    override fun initContentView(): Int {
        return R.layout.activity_choice_drive_time
    }
    private lateinit var filterType1LeftAdapter: MyAdapter
    private lateinit var filterType1RightAdapter: MyAdapter
//    var editDriveParam = EditDriveParam()
    private var reserveseries = ""
    private var reservespec = ""
    private var reserveday = ""
    private var reserveseriesname = ""
    private var reservespecname = ""
    override fun initViewModel(): ViewModel? {

        reserveseries = intent.getStringExtra("reserveseries")
        reservespec = intent.getStringExtra("reservespec")
        reserveday = intent.getStringExtra("reserveday")
        reserveseriesname = intent.getStringExtra("reserveseriesname")
        reservespecname = intent.getStringExtra("reservespecname")

        val factory = InjectorUtils.getChoiceDriveTimeActivityViewModelFactory(reserveseries,reservespec,reserveday,reserveseriesname,reservespecname)
        return ViewModelProviders.of(this, factory).get(ChoiceDriveTimeActivityViewModel::class.java)
    }

    override fun initView() {
        filterType1LeftAdapter = MyAdapter(R.layout.choice_drive_time_left_item, binding.viewModel)
        binding.driveTimeLeft.adapter = filterType1LeftAdapter

        binding.driveTimeRight.layoutManager = GridLayoutManager(this, 3)
        filterType1RightAdapter = MyAdapter(R.layout.choice_drive_time_right_item, binding.viewModel)
        binding.driveTimeRight.addItemDecoration(SpaceItemDecoration(this, 8, 8, 3))
        binding.driveTimeRight.adapter = filterType1RightAdapter
    }

    override fun initData() {
        binding.viewModel?.filterType1LeftDate?.observe(this, Observer { lists ->
            filterType1LeftAdapter.submitList(lists)
            filterType1LeftAdapter.notifyDataSetChanged()
        })
//
        binding.viewModel?.filterType1RgihtList?.observe(this, Observer { lists ->
            filterType1RightAdapter.submitList(lists)
            filterType1RightAdapter.notifyDataSetChanged()
        })

        binding.txtXiaoyouche.text = reserveseriesname + " " + reservespecname
        binding.txtDday.text = reserveday
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == 102) {
            data?.apply {
                var carBrandParam = getSerializableExtra("car") as CarBrandParam
                binding.viewModel?.setCarData(carBrandParam)
                binding.txtXiaoyouche.text = carBrandParam.seriesname + " " + carBrandParam.specname
            }
        }
    }


}
